package org.example.struct.array;

import com.alibaba.fastjson2.JSON;

/**
 * @author liyishan
 * @date 2023/8/22 11:33
 * @apiNote
 */

public class Test01365SmallerNumbersThanCurrent {
    public static void main(String[] args) {
        int[] nums = {8,1,2,2,3};
        int[] res = test(nums);
        System.out.println(JSON.toJSON(res));
    }

    public static int[] test(int[] nums) {
        int n = nums.length;
        int[] res = new int[n];
        for(int i = 0 ;i<n;i++){
            int count = 0 ;
            for(int j = 0;j<n;j++){
                if(nums[j]<nums[i]){
                    count++;
                }
            }
            res[i] = count;
        }
        return res;
    }

    public static int[] test1(int[] nums){
        int[] cnt = new int[101];
        int n =nums.length;
        for(int i = 0 ;i<n;i++){
            cnt[nums[i]]++;
        }
        for(int i =1;i<=100;i++){
            cnt[i] += cnt[i-1];
        }
        int[] ret = new int[n];
        for(int i = 0;i<n;i++){
            ret[i] = nums[i] == 0 ? 0:cnt[nums[i]-1];
        }
        return ret;
    }

}
